/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.source.web.direction;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.source.entity.direction.EleSourceDirectionGroup;
import com.thinkgem.jeesite.modules.source.service.direction.EleSourceDirectionGroupService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 方向资源管理Controller
 * @author ZC
 * @version 2017-04-24
 */
@Controller
@RequestMapping(value = "${adminPath}/source/direction/eleSourceDirectionGroup")
public class EleSourceDirectionGroupController extends BaseController {

	@Autowired
	private EleSourceDirectionGroupService eleSourceDirectionGroupService;
	
	@ModelAttribute
	public EleSourceDirectionGroup get(@RequestParam(required=false) String id) {
		EleSourceDirectionGroup entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = eleSourceDirectionGroupService.get(id);
		}
		if (entity == null){
			entity = new EleSourceDirectionGroup();
		}
		return entity;
	}
	
	@RequiresPermissions("source:direction:eleSourceDirectionGroup:view")
	@RequestMapping(value = {"list", ""})
	public String list(EleSourceDirectionGroup eleSourceDirectionGroup, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<EleSourceDirectionGroup> page = eleSourceDirectionGroupService.findPage(new Page<EleSourceDirectionGroup>(request, response), eleSourceDirectionGroup); 
		model.addAttribute("page", page);
		return "modules/source/direction/eleSourceDirectionGroupList";
	}

	@RequiresPermissions("source:direction:eleSourceDirectionGroup:view")
	@RequestMapping(value = "form")
	public String form(EleSourceDirectionGroup eleSourceDirectionGroup, Model model) {
		model.addAttribute("eleSourceDirectionGroup", eleSourceDirectionGroup);
		return "modules/source/direction/eleSourceDirectionGroupForm";
	}

	@RequiresPermissions("source:direction:eleSourceDirectionGroup:edit")
	@RequestMapping(value = "save")
	public String save(EleSourceDirectionGroup eleSourceDirectionGroup, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, eleSourceDirectionGroup)){
			return form(eleSourceDirectionGroup, model);
		}
		eleSourceDirectionGroupService.save(eleSourceDirectionGroup);
		addMessage(redirectAttributes, "保存方向资源成功");
		return "redirect:"+Global.getAdminPath()+"/source/direction/eleSourceDirectionGroup/?repage";
	}
	
	@RequiresPermissions("source:direction:eleSourceDirectionGroup:edit")
	@RequestMapping(value = "delete")
	public String delete(EleSourceDirectionGroup eleSourceDirectionGroup, RedirectAttributes redirectAttributes) {
		eleSourceDirectionGroupService.delete(eleSourceDirectionGroup);
		addMessage(redirectAttributes, "删除方向资源成功");
		return "redirect:"+Global.getAdminPath()+"/source/direction/eleSourceDirectionGroup/?repage";
	}
	@RequiresPermissions("source:direction:eleSourceDirectionGroup:check")
	@RequestMapping(value = "check")
	public String check(EleSourceDirectionGroup eleSourceDirectionGroup, RedirectAttributes redirectAttributes) {
		eleSourceDirectionGroupService.check(eleSourceDirectionGroup);
		addMessage(redirectAttributes, "审核方向资源成功");
		return "redirect:"+Global.getAdminPath()+"/source/direction/eleSourceDirectionGroup/?repage";
	}
}